package com.billionsfinance.hessian.core;

import com.billionsfinance.hessian.common.zookeeper.client.ClientSideZkEventConsumer;
import com.billionsfinance.hessian.common.zookeeper.client.ClientSideZkThread;
import com.billionsfinance.hessian.model.ServerInfo;

import java.util.Set;

/**
 * @ FileName: HessianClientInitFactory.java
 * @ Author: WeiHui-Z
 * @ Date: 2016-11-23  18:40
 * @ Version: v1.0.0
 */
public class HessianClientInitFactory extends HessianInitFactory {

	@Override
	protected void starterZookeeper() {
		Set<ServerInfo> serverInfoSet = scanPackages("");
		if (serverInfoSet != null && !serverInfoSet.isEmpty()) {
			Thread thread = new Thread(new ClientSideZkThread(zkConfig,serverInfoSet));
			thread.setDaemon(true);
			thread.setName("zookeeper注册");
			thread.start();

			// 启动时，启动event的消费者线程
			Thread zkConsumerThread = new Thread(new ClientSideZkEventConsumer());
			zkConsumerThread.setDaemon(true);
			zkConsumerThread.setName("Consumer for Zk event...");
			zkConsumerThread.start();
		}
	}

	@Override
	public void destroy() throws Exception {

	}
}
